#include <glib/gi18n.h>
static gboolean user_mode;
+static char *subpath;
static GOptionEntry options[] = {
{ "user-mode", 'U', 0, G_OPTION_ARG_NONE, &user_mode, "Do not change file ownership or initialze extended attributes", NULL },
+ { "subpath", 0, 0, G_OPTION_ARG_STRING, &subpath, "Checkout sub-directory PATH", "PATH" },
{ NULL }
};
char *resolved_commit = NULL;
const char *destination;
OstreeRepoFile *root = NULL;
- GFileInfo *root_info = NULL;
+ OstreeRepoFile *subtree = NULL;
+ GFileInfo *file_info = NULL;
GFile *destf = NULL;
context = g_option_context_new ("COMMIT DESTINATION - Check out a commit into a filesystem tree");
if (!ostree_repo_file_ensure_resolved (root, error))
goto out;
- root_info = g_file_query_info ((GFile*)root, OSTREE_GIO_FAST_QUERYINFO,
+ if (subpath)
+ {
+ subtree = (OstreeRepoFile*)g_file_resolve_relative_path ((GFile*)root, subpath);
+ }
+ else
+ {
+ subtree = g_object_ref (root);
+ }
+
+ file_info = g_file_query_info ((GFile*)subtree, OSTREE_GIO_FAST_QUERYINFO,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
cancellable, error);
- if (!root_info)
+ if (!file_info)
goto out;
if (!ostree_repo_checkout_tree (repo, user_mode ? OSTREE_REPO_CHECKOUT_MODE_USER : 0,
- destf, root, root_info, cancellable, error))
+ destf, subtree, file_info, cancellable, error))
goto out;
ret = TRUE;
g_clear_object (&repo);
g_clear_object (&destf);
g_clear_object (&root);
- g_clear_object (&root_info);
+ g_clear_object (&subtree);
+ g_clear_object (&file_info);
return ret;
}
set -e
-echo "1..26"
+echo "1..27"
. libtest.sh
$OSTREE cat test2 /yet/another/tree/green > greenfile-contents
assert_file_has_content greenfile-contents "leaf"
echo "ok cat-file"
+
+cd ${test_tmpdir}
+$OSTREE checkout --subpath /yet/another test2 checkout-test2-subpath
+cd checkout-test2-subpath
+assert_file_has_content tree/green "leaf"
+echo "ok checkout subpath"